<%@page import="com.liferay.portal.theme.ThemeDisplay"%>
<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<%@page import="com.crossriver.crgis.database.model.Contact_Information"%>
<%@page import="com.crossriver.crgis.database.model.History_Of_Information"%>
<%@page import="com.crossriver.crgis.database.service.persistence.Application_C_of_OUtil"%>
<%@ page import="com.crossriver.crgis.cofo.util.ApplicationCofOConstants" %>
<%@ page import="com.crossriver.crgis.database.model.Application_C_of_O" %>
<%@ include file="/init.jsp"%>

<liferay-portlet:actionURL name="saveApplicationHistory" var="saveApplicationHistory"></liferay-portlet:actionURL>
<%

Contact_Information contactInfo =
		(Contact_Information)request.getAttribute(
					ApplicationCofOConstants.IND_CONTACT_SESSION_ATTR);
List<History_Of_Information> history =(List<History_Of_Information>)
request.getAttribute(ApplicationCofOConstants.HISTORY_INFO_SESSION_ATTR);

Application_C_of_O applicatn = 
	Application_C_of_OUtil.findByPrimaryKey(contactInfo.getApplicationId());

portletDisplay= themeDisplay.getPortletDisplay();
String strPortletId= portletDisplay.getId();
	
%>


<liferay-ui:success key="application-history-save-success" message="application-history-save-success"></liferay-ui:success>

 <aui:form action="<%=saveApplicationHistory.toString() %>" method="post" name="saveApplicationHistory_fm">
 <% String app = applicatn.getApplication(); %>
 <div id="main">
	<%
	if("certification".equalsIgnoreCase(app)){
	%>
	<h1>Application for Certificate Of Occupancy</h1>
	<%
	}else if("re-certification".equalsIgnoreCase(app)){
	%>
	<h1>Application for Re-Certificate Of Occupancy</h1>
	<%
	}else {
	%>
	<h1>Application for State Land</h1>
	<%
	}
	%>
	
	<div class="content">
	
		<table width="100%" border="0" cellpadding="0" cellspacing="0">
			<tr>
			<td width="15%" valign="top">
				<aui:input name="applicationId" type="hidden" value="<%= contactInfo.getApplicationId() %>"></aui:input>
				<aui:input name="buttonClicked" type="hidden" value=""></aui:input>
				<table width="100%" id="steps" cellpadding="0" cellspacing="0">
       		<tr><td valign="middle" align="center">STEP 1</td></tr>
       		<tr><td valign="middle" align="center">STEP 2</td></tr>
	        <tr><td valign="middle" align="center">STEP 3</td></tr>
          <tr><td valign="middle" align="center" class="current">STEP 4</td></tr>
          <tr><td valign="middle" align="center">STEP 5</td></tr>
          <tr><td valign="middle" align="center">STEP 6</td></tr>
          <tr><td valign="middle" align="center">STEP 7</td></tr>
          <tr><td valign="middle" align="center">STEP 8</td></tr>                               
       	</table>
			</td>
			<td width="85%" valign="top">
				<table width="100%" id="mainform">
					<tr><td class="title" colspan="3">History of Application</td></tr>
					<tr>
						<td colspan="3" align="right">
							<hr>
							<aui:button type="button" value="Exit Application" onClick="exitApplication();"></aui:button>
             	
              
             	<aui:button type="submit" value="Save" onClick="setButtonClicked('btnSave');" ></aui:button>
            	<aui:button type="submit" value="Save and Continue" onClick="setButtonClicked('btnSaveAndContinue');" ></aui:button>
             	<aui:button type="button" value="Cancel Application" onClick="confirmPost()"></aui:button>
            </td>
					</tr>
					<tr>
						<td colspan="3"><br>
						<table id="tb-2" cellpadding="5">
							<tr><br>
								<td>Application Number of Previous Application (If any)</td>
							</tr>
							<tr>
								<td>
                              		<aui:select size="2" multiple="true" style="width:300px" label="" name="applicationHistory">
                              		<% 
                              		if (history != null)
                              		{  for (int i=0; i<history.size(); i++){
                              			%>
                              			<option >  <%= history.get(i).getOldApplicationId() %></option>
                              		<%
                              		}
                              		}
                              		%>
                              		</aui:select>
									<br />
                                    <input type="button" value="Delete List Item" onclick="return Del()" />
                                </td>
							</tr>
						</table>
						</td>
					</tr>
					<tr>
						<td colspan="3"><br>
							<span id="label">Has there been previous application by the applicant within the state?</span>
							<table width="100%" cellpadding="0" cellspacing="0">
							<tr><td><input name="yesorno" type="radio" id="question_no" value="no" rel="none" checked> No</td></tr>
							<tr><td><input name="yesorno" type="radio" id="question_yes" value="yes" rel="previous-application"> Yes</td></tr>
							<tr rel="previous-application">
								<td><br>
									<span id="label" for="txtPreviousApplication">If Yes,Please Enter Previous Application File Number</span> 
									<input type="text" id="txtNewOption" style="cursor: text" maxlength="10" name="txtPreviousApplication"> 
									<input type="button" id="btnAdd" value="Add New Option"  onclick="Add();">
								</td>
							</tr>
						</table>
						</td>
					</tr>
					<tr>
						<td colspan="3"><br>
							<hr>
							<p>Please, Kindly ensure that this form is properly filled and
							all information provided here are accurate. All fields asterisk in
							"red" are compulsory, as the form would not be processed if the
							fields are left empty.</p>
						</td>
					</tr>
					<tr>
					 	<td colspan="3" align="right"><br>
							<aui:button type="button" value="Exit Application" onClick="exitApplication();"></aui:button>
             	
              
             	<aui:button type="submit" value="Save" onClick="setButtonClicked('btnSave');" ></aui:button>
            	<aui:button type="submit" value="Save and Continue" onClick="setButtonClicked('btnSaveAndContinue');" ></aui:button>
             	<aui:button type="button" value="Cancel Application" onClick="confirmPost()"></aui:button>
           	</td>
					</tr>
				</table>
			</td>
			</tr>
		</table>
	</div>
</div>
</aui:form>

	<liferay-portlet:actionURL name="exitApplication" var="exitApplication"></liferay-portlet:actionURL>
	<form name="<portlet:namespace/>exitApplication_fm" method="post"	id="<portlet:namespace/>exitApplication_fm" action="<%=exitApplication.toString()%>"></form>
	<script type="text/javascript">
	<!--
	function exitApplication()
	{
		document.forms["<portlet:namespace/>exitApplication_fm"].submit();
	}
	//-->
	</script>

<script type="text/javascript">
function setButtonClicked(id)
{
    //alert(id);
   document.<portlet:namespace/>saveApplicationHistory_fm.<portlet:namespace/>buttonClicked.value=id;
  // alert(document.<portlet:namespace/>quick_add_account_fm.<portlet:namespace/>buttonClicked.value);
    //document.getElementById('jspPage').value=id;
}

	function Add() {
        var  list = document.getElementById('<portlet:namespace/>applicationHistory');
        var text = document.getElementById('txtNewOption');
        var newlistoption = document.createElement('option');
        
        newlistoption.text = text.value;
        newlistoption.value = text.value;
        list.add(newlistoption);
        text.value="";
        text.focus();
     }
     
     function Del() {
        var list  = document.getElementById('<portlet:namespace/>applicationHistory');
        if(list.options.length > 0)
          {
            for(var i = list.options.length - 1; i >= 0; i--)
              {
                if(list.options[i].selected)
                  {
                    list.remove(i);
                    return false;
                  }
              }
          }
        else
          {
            window.alert('List is Empty!');
          }
     }

     function hasOptions(obj){if(obj!=null && obj.options!=null){return true;}return false;}
     
     function selectAllOptions(){
         var obj = document.getElementById('<portlet:namespace/>applicationHistory');
         if(!hasOptions(obj)){return;}for(var i=0;i<obj.options.length;i++){obj.options[i].selected = true;}
      }
     
</script>

<script type="text/javascript">
<!--
	function confirmPost()
	{
	var agree=confirm("Cancelling the process will delete the record you have entered into the portal for this application. Do you want to proceed?");
	if (agree){
		document.forms["<portlet:namespace/>deleteApplication_fm"].submit();
		return true ;
	}
	else{
		return false ;
	}
	}
//-->
</script>

<liferay-portlet:actionURL name="deleteApplication" var="deleteApplication"></liferay-portlet:actionURL>
 <aui:form action="<%=deleteApplication.toString() %>" method="post" name="deleteApplication_fm">
  	<aui:input name="applicationId" type="hidden" value="<%= contactInfo.getApplicationId() %>"></aui:input>
 </aui:form>
 
 